package net.meblabs.bookapp.util;

import java.beans.PropertyEditorSupport;

import net.meblabs.bookapp.util.Message.MessageType;

public class MessagePropertyEditor extends PropertyEditorSupport {

	private Message message;

	@Override
	public Object getValue() {
		return message;
	}

	@Override
	public void setValue(Object value) {
		this.message = (Message) value;
	}

	@Override
	public String getAsText() {
		return message.getType().toString() + ":" + message.getText();
	}

	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		String[] tokens = text.split(":");
		message = new Message(MessageType.valueOf(tokens[0]), tokens[1]);
	}
}
